package com.dao;

import com.beans.MenuInfo;
import com.jdbc.DBUtil;

import java.util.List;

public class MenuDao {
    public List<MenuInfo> getMenuList(int parentId){
        String sql="select * from menuInfo where parentId=?";
        List<MenuInfo> menuList= DBUtil.getList(sql, MenuInfo.class,parentId);
        //让每个菜单,都把属于它的子菜单查出来
        for(MenuInfo m:  menuList) {
            if(m.getParentId()==0) {
                m.setSubMenuList( getMenuList(m.getId()) );
            }
        }
        return menuList;
    }
    public List<MenuInfo> getMenuList(int parentId, int roleId){
        String sql="select * from menuInfo where parentId=? and id in (select menuId from roleMenu where roleId=?)";
        List<MenuInfo> menuList=DBUtil.getList(sql, MenuInfo.class,parentId ,roleId);
        //让每个菜单,都把属于它的子菜单查出来
        for(MenuInfo m: menuList) {
            if(m.getParentId()==0) {
                m.setSubMenuList( getMenuList(m.getId(),roleId) );
            }
        }
        return menuList;
    }
}
